package com.beici.vueblogapp.controller;

import com.beici.vueblogapp.model.blogComments;
import com.beici.vueblogapp.model.results;
import com.beici.vueblogapp.model.userBlog;
import com.beici.vueblogapp.service.blogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@CrossOrigin
public class blogController {

    @Autowired
    private blogService blogSerivceImp;

    //  获取分页的文章
    @PostMapping("/getBlogAll/{page}")
    @ApiOperation(value = "获取分页的文章")
    public results getBlogAll(@PathVariable Integer page){
        return blogSerivceImp.getBlogAll(page);
    }
    // 获取所有文章条数 查看可以分几页
    @PostMapping("/getPageAll")
    @ApiOperation(value = "获取可分页的页数")
    public results getPageAll(){
        return blogSerivceImp.getPageAll();
    }
    //获取精选文章
    @ApiOperation(value = "获取精选的博客")
    @PostMapping("/getGoodsBlog")
    public results getGoodsBlog(){
       return blogSerivceImp.getGoodsBlog();
    }

    //查看文章
    @PostMapping("/getBlog/{Id}")
    @ApiOperation(value = "获取指定博客")
    public results getBlog(@PathVariable Integer Id){
        return blogSerivceImp.getBlog(Id);
    }

    //搜索文章
    @PostMapping("/searchBlog/{content}")
    @ApiOperation(value = "搜索博客")
    public results searchBlog(@PathVariable String content){
        return blogSerivceImp.searchBlog(content);
    }

    //查看评论 绑定 文章
    @PostMapping("/getComments/{Id}")
    @ApiOperation(value = "获取指定文章的评论")
    public results getComments(@PathVariable Integer Id){
        return blogSerivceImp.getComments(Id);
    }

    //评论
    @PostMapping("/addComment/{Id}/{username}/{content}")
    @ApiOperation(value = "评论")
    public results addComment(@PathVariable("Id")Integer Id , @PathVariable("username") String username, @PathVariable("content") String content, HttpServletRequest request){
        //获取在过滤器过滤出来的数据
       String filterContent = (String) request.getAttribute("content");
       return blogSerivceImp.addComment(Id,username,filterContent);

    }
    //提交博客
    @ApiOperation(value = "提交博客")
    @PostMapping("/submitBlog")
    public results submitBlog(String title
                                ,String summary
                                ,String banner
                                ,String content
                                ,boolean isHot
                                ,boolean isTop){
        return blogSerivceImp.submitBlog(title,summary,banner,content,isHot,isTop);
    }

    //热搜-置顶
    @ApiOperation(value = "管理热搜与置顶")
    @PostMapping("/isHotAndisTop")
    public results isHot(Integer id,boolean isHot,boolean isTop){
        return blogSerivceImp.isHotAndisTop(id,isHot,isTop);
    }
    //删除
    @PostMapping("/del")
    @ApiOperation(value = "删除指定博客")
    public results del(Integer id){
        return blogSerivceImp.del(id);
    }
}
